import { apiInvmbPage } from '@/api/url/libraryModules';
import router from '@/router';
import { isNullPm } from '@/utils/baseMethods';
import { reactive } from 'vue';

export default function importConfig() {
  const base = reactive<any>({
    size: 'medium',
    columns: [],
    searchConfig: null,
    config: [],
    pagination: {
      defaultPageSize: 10,
      total: 10, //总条数
      current: 1,
      pageSize: 10,
      showTotal: true,
      showPageSize: true,
      pageSizeOptions: [10, 20, 30, 40, 50],
    },
    loading: true,
    tabelList: null,
    checkFrom: {
      mb001: null,
      mb002: null,
    },
  });

  /**
   * @exports init 初始化
   */
  const init = () => {
    base.columns = columnsConfig;
    base.config = config;
    base.loading = false;
    getTabel();
  };

  const getTabel = () => {
    const steam = {
      size: base.pagination.current,
      pagesize: base.pagination.pageSize,
    };

    Object.keys(base.checkFrom).map((res: any) => {
      if (!isNullPm(base.checkFrom[res])) steam[res] = base.checkFrom[res];
    });

    apiInvmbPage(steam).then((res: any) => {
      if (res.code === 1) {
        base.tabelList = res.data.records;
        base.pagination.total = res.data.total;
      }
    });
  };

  /**
   * @exports opArticleNumber 跳转到viewImgPad
   * @param param
   */
  const opArticleNumber = (param) => {
    // console.log(param, '==>viewImgPad')
    router.push({ path: '/itemDetails', query: { UID: param.mb001.trim() } });
    // apiSfcte
  };

  const columnsConfig = [
    {
      title: '品号',
      dataIndex: 'mb001',
      align: 'center',
    },
    {
      title: '品名',
      dataIndex: 'mb002',
      align: 'center',
    },
    {
      title: '规格',
      dataIndex: 'mb003',
      align: 'center',
    },
    // {
    //     title: '商品描述',
    //     dataIndex: 'mb009',
    //     checked: true,
    // },
    // {
    //     title: '生产供应商',
    //     dataIndex: 'mb032',
    //     checked: true,
    // },
    {
      title: '标准工艺路线品号',
      dataIndex: 'mb010',
      align: 'center',
    },
    // {
    //     title: '类型',
    //     dataIndex: '',
    //     checked: true,
    // },
    {
      title: '操作',
      slotName: 'option',
    },
  ];

  const config = ['add', 'Download', 'derive'];

  /**
   * @exports tapDate 触发搜索
   * @param param
   */
  const tapDate = (param) => {
    // console.log(param, '==>tapDate')
    // console.log(getInitParam(queryDataFilter(param)), '==>tapDate')
  };

  /**
   * @exports handlePageChange 页码变化时
   */
  const handlePageChange = (page: number) => {
    base.pagination.current = page;
    init();
  };
  const handlePageSizeChange = (pageSize: number) => {
    base.pagination.pageSize = pageSize;
    init();
  };

  return {
    base,
    opArticleNumber,
    init,
    tapDate,
    handlePageChange,
    handlePageSizeChange,
  };
}
